package com.eastfair.config.controller.entitycontroller;

import com.eastfair.config.entity.PageTDK;
import com.eastfair.config.service.entityservice.PageTDKService;
import com.eastfair.core.base.R;
import com.eastfair.projectcore.vo.ConfigAttributeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TDK控制类
 * <p>
 * Date:2021/8/7
 * Time:15:37
 *
 * @author zjn
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/pageTDK")
@Api(value = "TDK控制类", tags = "TDK控制类")
public class PageTDKController {

    @Autowired
    private PageTDKService pageTDKService;

    /**
     * 获取TDK属性信息
     *
     * @return
     */
    @GetMapping("/getAttributes")
    @ApiOperation(value = "获取TDK属性信息", notes = "获取TDK属性信息")
    public R<List<ConfigAttributeVO>> getPageTDKAttributes() {
        return R.success(pageTDKService.getAttributes());
    }

    /**
     * 获取TDK列表
     *
     * @param pageTDK TDK列表过滤条件
     * @return
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取TDK列表", notes = "获取TDK列表")
    public R<List<PageTDK>> getList(@RequestBody(required = false) PageTDK pageTDK) {
        return R.success(pageTDKService.getList(pageTDK));
    }

    /**
     * 获取TDK
     *
     * @param flagId 标识id
     * @return
     */
    @GetMapping("/get/{flagId}")
    @ApiOperation(value = "获取TDK", notes = "获取TDK")
    public R<PageTDK> getPageTDK(@PathVariable("flagId") Long flagId) {
        return pageTDKService.get(flagId);
    }

    /**
     * 新增TDK
     *
     * @param pageTDK TDK实体
     * @return 是否成功
     */
    @PostMapping("/saveEntity")
    @ApiOperation(value = "新增TDK", notes = "新增TDK")
    public R<Boolean> saveEntity(@RequestBody PageTDK pageTDK) {
        return pageTDKService.saveEntity(pageTDK);
    }

    /**
     * 删除TDK
     *
     * @param flagId TDK标识id
     * @return 是否成功
     */
    @DeleteMapping("/{flagId}")
    @ApiOperation(value = "删除TDK", notes = "删除TDK")
    public R<Boolean> deleteEntity(@PathVariable("flagId") Long flagId) {
        return pageTDKService.deleteEntity(flagId);
    }

    /**
     * 修改TDK信息
     *
     * @param pageTDK TDK信息
     * @return 是否成功
     */
    @PutMapping("/updateEntity")
    @ApiOperation(value = "修改TDK信息", notes = "修改TDK信息")
    public R<Boolean> updateEntity(@RequestBody PageTDK pageTDK) {
        return pageTDKService.updateEntity(pageTDK);
    }

}
